<?php
global $_W,$_GPC;
load()->func('tpl');
	$rid=$_GPC["rid"];
	$acid=$_W['uniacid'];
// 	$openid = $_W["openid"];
// 	$nick=$_W['fans']['nickname'];
// 	$headimg=$_W['fans']['tag']['avatar'];
	if (strpos($_SERVER['HTTP_USER_AGENT'],'MicroMessenger') !== false ) {
	}else{
		$_W["openid"]='oU4go0msnyP2JizVuKdoNoZ1xLqo';
		$_W['fans']['tag']['avatar']='http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83erY5c9JicvJJGHJqZV17FdvGOsfwSUIZ3Mu8O0lgR1sibw1c7fibMl9fLBjhrZL7m3QMU6wUIqE5rwBA/132';
		$_W['fans']['nickname']='让心灵去旅行';
	}
	$openid = $_W ['openid'];
	$nick=$_W['fans']['nickname'];
	$headimg=$_W['fans']['tag']['avatar'];
	
	$reply=pdo_fetch("SELECT * FROM " . tablename('dt_question_reply') . " WHERE rid = :rid ", array(':rid' => $rid));
	$userinfo = pdo_fetch("SELECT * FROM ". tablename("dt_userinfo")." WHERE openid=:openid and rid=:rid ORDER BY ID DESC LIMIT 1" , array(":openid"=>$openid,":rid"=>$rid));
	$userpoints = pdo_fetch("SELECT * FROM ". tablename("dt_userpoints")." WHERE openid=:openid and rid=:rid ORDER BY ID DESC LIMIT 1" , array(":openid"=>$openid,":rid"=>$rid));
	//$usercount = pdo_fetch("SELECT * FROM ". tablename("dt_usercount")." WHERE openid=:openid and rid=:rid LIMIT 1" , array(":openid"=>$openid,":rid"=>$rid));
	if(!empty($userinfo)){
		$id=intval($userinfo["id"]);
		$shyucount=intval($userinfo["shyucount"]);
		$points=$userpoints["points"];
		$sytime=$userpoints["sytime"];
	}
	
	//是否分参答案
	$addtime=date('Y-m-d',time());
	$usershare=pdo_fetch("SELECT * FROM ". tablename("dt_usershare")." WHERE openid=:openid and rid=:rid and addtime=:addtime
			 ORDER BY ID DESC LIMIT 1" , array(":openid"=>$openid,":rid"=>$rid,":addtime"=>$addtime));


	/**
	 * 分享
	 */
	$sharetitle=$reply["sharetitle"];//分享标题
	$sharecontent=$reply["sharecontent"];//分享内容
	$shareimg=$_W['attachurl'].$reply["shareimg"];//分享图片
	$isshareadd=$reply["isshareadd"];//是否 分享增加一次
	$sharelink="";
	$huodongname=$reply["huodongname"];
	$color=$reply["color"];
	//奖励设置
	
	if($isshareadd==0){
		$sharelink = $_W ['siteroot'] . 'app/' . $this->createMobileUrl ( 'index', array ('rid' => $rid));
	}else{
		$sharelink=$_W ['siteroot'] . 'app/' . $this->createMobileUrl ( 'index', array ('rid' => $rid,'fromid'=>$openid));
	}
	$sharelink = str_replace ( './', '', $sharelink );//分享链接
	
	//如果超过分享次数上限
	$sharelist=pdo_fetchall("select * from ".tablename("dt_usershare")." where fromuserid=:fromid and rid=:rid",array(":fromid"=>$openid,":rid"=>$rid));
	$is_max=0;
	if($reply["maxcount"]!=0 && !empty($reply["maxcount"]) && $reply["maxcount"]<=count($sharelist)){
		$is_max=1;
	}
	
include $this->template('chengji');